package com.wwy.arithmetic.newsuanfa;

/**
 * @author 王伟羽
 * @program: arithmetictest
 * @description: 删除重复元素
 * @create: 2025/04/07
 */

public class Shanchuyuansu {

    public ListNode deleteDuplicates(ListNode head) {
        if(head.next ==null){
            return head;
        }
        List cur = head;
        while (cur.next != null){
            if(cur.val == cur.next.val){
                cur.next = cur.next.next;
            }else{
                cur = head.next;
            }
        }
        return head;
    }

    //合并两个有序数组
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int a = m-1 ;
        int b  = n-1;
        int c = n+m-1;
        while(b>=0 && a>=0){
            if(nums1[a]>nums2[b]){
                nums1[c--] = nums1[a--];
            }else{
                nums1[c--] = nums2[b--];
            }

        }
        while(b>=0){
            nums1[c--] = nums2[b--];
        }
    }

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int a = m+n-1;
        int b = m-1;
        int c = n-1;
        while (b>=0&&c>=0){
            if(nums1[b]>nums2[c]){
                nums1[a--] = nums1[b--];
            }else{
                nums1[a--]=nums2[c--];
            }
        }
        while (c>=0){
            nums1[a--] = nums2[c--];
        }
    }
}
